package com.ysm.smfu.welcome;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.ysm.smfu.R;
import com.ysm.smfu.utils.UIUtils;

//引导页使用的pageview适配器
public class BasePagerAdapter extends PagerAdapter {
    private int[] views;

    public BasePagerAdapter(int[] views) {
        this.views = views;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public int getCount() {
        return views.length;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager) container).removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = UIUtils.inflate(R.layout.item_viewpager);
        ImageView iv= (ImageView) view.findViewById(R.id.iv);
        iv.setImageResource(views[position]);
        container.addView(view);
        return view;
    }
}
